package com.itheima.dao;


import com.itheima.domain.Person;


public class PersonDao {
    private  static  Person[] persons = new Person[10];
    static {

            Person p = new Person("12321","12321","12321","12321");
            persons[0]= p;
    }
    public boolean add(Person s) {
        int index = -1;
        while(true){
            index++;
            if(persons[index] == null){
                persons[index] = s;
                break;
            }
            if(index>=10){
                break;
            }
        }
        if(index>=10){
            return false;
        }else {
            return true;
        }
    }

    public Person[] select() {
        return persons;
    }
    public int isExist(String nextSid) {
        Person [] select = select();
        int index = -1;
        for (int i = 0; i < select.length; i++) {
            try{
                if(nextSid.equals(select[i].getSid())){
                      index++;
                   }
                }catch (Exception e){
                e.fillInStackTrace();
            }
        }
        return index;
    }

    public void delete(int index) {
        persons[index]=null;
    }
}
